package com.panda.web.controller.commons;

import com.panda.common.annotation.Log;
import com.panda.common.core.controller.BaseController;
import com.panda.common.core.domain.AjaxResult;
import com.panda.common.core.domain.R;
import com.panda.common.enums.BusinessType;
import com.panda.web.domain.vo.YjsEditionVO;
import com.panda.web.entity.commons.GraduateEdition;
import com.panda.web.service.commons.IGraduateEditionService;
import com.panda.web.utils.pageutils.PageResult;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


/**
 * 专业分类Controller
 *
 * @author cpanda
 * @date 2025-03-05
 */
@CrossOrigin
@RestController
@RequestMapping("/web/Graduate/edition")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class GraduateEditionController extends BaseController {
    private final IGraduateEditionService editionService;

    /**
     * 查询专业分类列表
     */
    @GetMapping("/list")
    public PageResult<GraduateEdition> List(GraduateEdition edition,
                                           @RequestParam("pageNum") Integer pageNum,
                                           @RequestParam("pageSize") Integer pageSize) {
        //返回分页信息
        PageResult<GraduateEdition> voList = editionService.PageList(edition,pageNum,pageSize);
        return voList;
    }


    /**
     * 查询专业分类列表 无分页
     */
    @GetMapping("/choiceList")
    public R choiceList(GraduateEdition edition) {
        List<GraduateEdition> voList = editionService.choiceList(edition);
        return R.ok(voList,"ok");
    }
    /**
     * 多级分类搜索查询（硕士专业）
     */
    @GetMapping("/tree")
    public R getSpecialTree(GraduateEdition edition){
        List<YjsEditionVO> vo  = editionService.getGraduateTree(edition);
        return R.ok(vo,"ok");
    }
    /**
     * 获取专业分类详细信息
     */
    @GetMapping(value = "/{specialId}")
    public AjaxResult getInfo(@PathVariable("specialId") Long specialId) {
        return AjaxResult.success(editionService.selectById(specialId));
    }

    /**
     * 新增专业分类
     */
    @Log(title = "专业分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GraduateEdition edition) {
        return toAjax(editionService.insert(edition));
    }

    /**
     * 修改专业分类
     */
    @Log(title = "专业分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GraduateEdition edition) {
        return toAjax(editionService.updateEditionById(edition));
    }

    /**
     * 删除专业分类
     */
    @Log(title = "专业分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{specialIds}")
    public AjaxResult remove(@PathVariable Long[] specialIds) {
        return toAjax(editionService.removeByEditionIds(Arrays.asList(specialIds)));
    }


}
